package com.mdp.im.core.subscriber.action.impl.msgaction;

import com.alibaba.fastjson.JSONObject;
import com.mdp.im.core.scbscriber.api.action.PrichatMsgAction;
import com.mdp.im.core.service.admin.BlackUserFrendsService;
import com.mdp.im.core.utils.msg.MsgAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("subscriber.PrichatMsgActionAction")
/**
 * msgId:xxxx,
 * groupId:xxxxx,
 * msgType:prichat,
 * action:newMessage,
 * sendUserid:xxx,
 * toUserid:xxxxx,
 * sourceMsgId:xxxxx,//agreeJoinFrend/refuseJoinFrend时必须
 * msgAction: inviteJoinFrend/agreeJoinFrend/refuseJoinFrend/delJoinFrend/blackJoinFend/removeBlackFrend 邀请/同意/拒绝/删除/拉黑/拉出黑名单
 * 
 * @author qqkj
 *
 */
public class InviteJoinFrendMsgAction implements PrichatMsgAction {

	@Autowired
	BlackUserFrendsService blackUserFrendsService;
	
	@Override
	public void doAction(JSONObject message) {
		String msgAction=message.getString("msgAction");
		String sendUserid=message.getString("sendUserid");
		String toUserid=message.getString("toUserid"); 
		if(MsgAction.prichat_delJoinFrend.equals(msgAction)) {
			blackUserFrendsService.putBlack(sendUserid, toUserid);
			blackUserFrendsService.putBlack(toUserid, sendUserid);
			 
		}else if(MsgAction.prichat_blackJoinFrend.equals(msgAction)) {
			blackUserFrendsService.putBlack(sendUserid, toUserid);
		}else if(MsgAction.prichat_removeBlackFrend.equals(msgAction)) {
			blackUserFrendsService.removeBlack(sendUserid, toUserid);
		}
	}

	@Override
	public boolean suportMsgAction(String msgAction) {
		// TODO Auto-generated method stub
		return MsgAction.prichat_inviteJoinFrend.equals(msgAction)||MsgAction.prichat_agreeJoinFrend.equals(msgAction)||MsgAction.prichat_refuseJoinFrend.equals(msgAction)||MsgAction.prichat_delJoinFrend.equals(msgAction)||MsgAction.prichat_blackJoinFrend.equals(msgAction);
	}

}
